package Java0108;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class Java05 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        //java基础api体系：集合，异常。IO
        //java高级api体系：网络。反射。线程
        // 反射理解：一种看透java的能力。
        // 类           java.lang.class
        //成员变量        java.lang.reflect.Filed
        //成员方法         java.lang.reflect.Method
        //成员函数        java.lang,reflect.Contructor
        Class  c = Class.forName("person");
        //成员变量
        Field[] declaredFields = c.getDeclaredFields();
        for (Field f : declaredFields) {
            System.out.println(f.getName());
        }
        //成员方法
        Method[] declaredMethods = c.getDeclaredMethods();
        for (Method m : declaredMethods) {
            System.out.println(m.getName());
        }
        Constructor[] declaredConstructors = c.getDeclaredConstructors();
        for (Constructor m : declaredConstructors) {
            System.out.println(m.getName());



    } //获取父类
        Class superclass = c.getSuperclass();
        System.out.println(superclass.getName());
        //获取接口
        Class[] interfaces = c.getInterfaces();
        for (Class i : interfaces) {
            System.out.println(i.getName());
        }
        //使用反射api创建对象
        Object o = (Person)c.newInstance();

    }

}
class Person{
    String name;
    int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
